/**
 * Copyright(c) Hainan eKing Technology co., LTD
 *
 * @date 2013年9月11日
 * 	
 * Original Author: 郑兴(zhengxing)
 *
 * ChangeLog
 *
 */
package com.hnas.sys.core.spring;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;

import com.hnas.sys.service.system.UserService;
import com.hnas.sys.service.system.dto.DTOUser;

/**
 * @author 郑兴(zhengxing)
 *
 */
public class ADTUserDetailsService implements UserDetailsService {
	private Logger log = LoggerFactory.getLogger(ADTUserDetailsService.class);
	@Autowired
	private UserService userService;
	
	/* (non-Javadoc)
	 * @see org.springframework.security.core.userdetails.UserDetailsService#loadUserByUsername(java.lang.String)
	 */
	public UserDetails loadUserByUsername(String userName)
			throws UsernameNotFoundException {
		log.debug("Load user[" + userName + "].");
		try{
		DTOUser user = userService.findByUserName(userName);
		if (null==user)
			throw new UsernameNotFoundException("在数据库中找不到该用户！");
		return user;
		}catch(Exception ex){
			log.error("",ex);
		}
		return null;
	}

}
